<!DOCTYPE html>
<!--物料申购中,物料添加时除了数量填写,其他的都设定为只是readOnly-->
<!--物料的项目选择,需要加载tree时根据目录结构展示项目列表-->
<!--物料的物料选择,需要加载物料tree时根据目录结构展示物料列表-->

<!--dlg4: 物料申购数量填写弹出窗-->
<html>
<head>
    <meta charset="UTF-8">
    <title>物料申购单</title>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/default/easyui.css"></link>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/icon.css"></link>
    <script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/static/js/date.js"></script>
    <script type="text/javascript">
        var url;

        //禁止整体该页面的右键弹出html相关,不阻碍easyui右键
        $(function () {
            $(document).bind('contextmenu', function (e) {
                e.preventDefault();
                $('#tree-0').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            });
        });
        //加载tree类别
        function openProjListChoose() {
            $("#projList").dialog("open").dialog("setTitle", "进入项目选择");
            $("#projTree").tree({
                url: '/admin/project/loadProjectTree',
                onLoadSuccess: function (node, data) {
                    $("#projTree").tree('expandAll');
                },
                onDblClick: function (node) {

                },
                //右键选择树形菜单操作
                onContextMenu: function (e, node) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                },
                //单击某类别 展示不同详细和按钮选择
                onClick: function (node) {
                    if (node.attributes.state == 2) { // 假如是二级菜单,可以删除
                        $("#projNameList").datagrid('load', {
                            "w_id": node.id
                        });
                    } else if (node.attributes.state == 1) {
                        $("#projNameList").datagrid('load', {
                            "o_id": node.id
                        });
                    }
                }
            });
            loadDataGrid();
        }

        //加载项目数据表格
        function loadDataGrid() {
            $("#projNameList").datagrid({
                //双击事件
                onDblClickRow: function (index, row) {
                    $("#projId").val(row.id);
                    $("#projName").val(row.xiangmumingcheng);
                    $("#projList").dialog("close");
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                },
            });
        }

        //加载物料数据表格
        function loadWuliaoDataGrid() {
            $("#dg3").datagrid({
                //     // 双击事件
                //之后onLoadSuccess加载这两种方法
                //悬停提示tooltip
                onLoadSuccess: function (data) {
                    $(this).datagrid('tooltip');
                    $(this).datagrid('fixRownumber');
                },
                onDblClickRow: function (index, row) {
                    openGoodsChooseDialog(); //打开物料申购窗口(填写物料申请数量)
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    $(this).datagrid("clearSelections"); //取消所有选中项
                    $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                    $('#grid-data').menu('show', {
                        left: e.pageX,//在鼠标点击处显示菜单
                        top: e.pageY
                    });
                    e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                },
            });
        }

        //之下为鼠标悬停table上展示单个字段的tooltip
        $.extend($.fn.datagrid.methods, {
            tooltip: function (jq, fields) {
                return jq.each(function () {
                    var panel = $(this).datagrid('getPanel');
                    if (fields && typeof fields == 'object' && fields.sort) {
                        $.each(fields, function () {
                            var field = this;
                            bindEvent($('.datagrid-body td[field=' + field + '] .datagrid-cell', panel));
                        });
                    } else {
                        bindEvent($(".datagrid-body .datagrid-cell", panel));
                    }
                });

                function bindEvent(jqs) {
                    jqs.mouseover(function () {
                        var content = $(this).text();
                        if (content && content != "") {
                            $(this).tooltip({
                                content: content,
                                trackMouse: true,
                                deltaX: 15,
                                deltaY: -5,
                                onShow: function () {
                                    $(this).tooltip('tip').css({
                                        backgroundColor: '#f7f5d1',
                                        borderColor: 'black'
                                    });
                                }
                            }).tooltip('show');
                        }
                    });
                }
            }
        });

        $.extend($.fn.datagrid.methods, {
            fixRownumber : function (jq) {
                return jq.each(function () {
                    var panel = $(this).datagrid("getPanel");
                    //获取最后一行的number容器,并拷贝一份
                    var clone = $(".datagrid-cell-rownumber", panel).last().clone();
                    //由于在某些浏览器里面,是不支持获取隐藏元素的宽度,所以取巧一下
                    clone.css({
                        "position" : "absolute",
                        left : -1000
                    }).appendTo("body");
                    var width = clone.width("auto").width();
                    //默认宽度是25,所以只有大于25的时候才进行fix
                    if (width > 25) {
                        //多加5个像素,保持一点边距
                        $(".datagrid-header-rownumber,.datagrid-cell-rownumber", panel).width(width + 5);
                        //修改了宽度之后,需要对容器进行重新计算,所以调用resize
                        $(this).datagrid("resize");
                        //一些清理工作
                        clone.remove();
                        clone = null;
                    } else {
                        //还原成默认状态
                        $(".datagrid-header-rownumber,.datagrid-cell-rownumber", panel).removeAttr("style");
                    }
                });
            }
        });

        //项目列表选择
        // function openProjListChoose(){
        //     $("#projList").dialog("open").dialog("setTitle","进入项目选择");
        //     $("#projTree").tree({
        //         url:'/admin/project/loadProjectTree',
        //         onLoadSuccess:function(node,data){
        //             var rootNode = $("#tree").tree('getRoot');
        //             $("#tree").tree('expandAll');
        //         },
        //         onClick:function(node){
        //             // if(node.attributes.state==0){ //如果是叶子节点,删除按钮恢复可用,只是展示时取消展示就可以了
        //             //
        //             // }
        //             $("#dg4").datagrid('load',{
        //                 "id":node.id
        //             });
        //         }
        //     });
        // }
        //保存项目选择 (分别根据type 1 or 2 保存项目分类或是项目列表)
        function saveProjChoose(type) {
            if (type == 1) {
                var node = $('#projTree').tree('getSelected'); // 获取选中节点
                $("#projId").val(node.id);
                $("#projName").val(node.text);
                $("#projList").dialog("close");
            } else if (type == 2) {
                //获得 选中的行
                var row = $('#projNameList').datagrid('getSelected');
                $("#projId").val(row.id);
                $("#projName").val(row.xiangmumingcheng);
                $("#projList").dialog("close");
            }
        }

        //打开物料选择的大窗口
        function openShengouDetailsAddDialog() {
            $("#dlg").dialog("open").dialog("setTitle", "物料选择");
            loadWuliaoDataGrid();
            $("#tree").tree({
                url: '/admin/wuliaoTree/loadWuliaoTree',
                onLoadSuccess: function (node, data) {
                    var rootNode = $("#tree").tree('getRoot');
                    $("#tree").tree('expand', rootNode.target);
                },
                //单击某类别 展示不同详细和按钮选择
                onClick: function (node) {
                    if (node.attributes.state == 2) { // 假如是二级菜单,可以删除
                        $("#dg3").datagrid('load', {
                            "w_id": node.id
                        });
                    } else if (node.attributes.state == 1) {
                        $("#dg3").datagrid('load', {
                            "o_id": node.id
                        });
                    }
                }
            });
        }

        // 更改物料
        function openShengouDetailsModifyDialog() {
            $("#saveAndAddNextBuuton").hide();
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length != 1) {
                $.messager.alert("系统提示", "请选择一个物料！");
                return;
            }
            var row = selectedRows[0];
            console.log(row);
            $("#dlg4").dialog("open").dialog("setTitle", "修改申购单物料");
            $("#fm4").form("load", row);
            $("#fm5").form("load", row);

            $("#lastReturnPrice").val("￥" + row.lastPurchasingPrice);
            $("#price").numberbox("setValue", row.price);
            $("#num").numberbox("setValue", row.num);
            $("#num").focus();
            $("#action").val("modify");
            $("#rowIndex").val($("#dg").datagrid("getRowIndex", row));
        }

        function deleteShengouDetails() {

            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length != 1) {
                $.messager.alert("系统提示", "请选择要删除的物料！");
                return;
            }
            $.messager.confirm("系统提示", "您确定要删除这个物料吗？", function (r) {
                if (r) {
                    $('#dg').datagrid('deleteRow', $("#dg").datagrid("getRowIndex", selectedRows[0]));
                    setReturnListAmount();
                }
            });
        }

        //[unused] 计算总价格,暂时用不到
        function setReturnListAmount() {
            var rows = $("#dg").datagrid("getRows");
            var amount = 0;
            for (var i = 0; i < rows.length; i++) {
                var row = rows[i];
                amount += row.total;
            }
            $("#amountPayable").val(amount.toFixed(2));
            $("#amountPaid").val(amount.toFixed(2));
        }

        //获取申购单单号
        $(document).ready(function () {
            $("#dh").load('/admin/shengoudan/getShengouNumber');
        });

        // 申购单保存,首先将子表中的进行json化,控制层解析json转回对象进行数据库保存
        function saveReturnGoods() {
            var goodsJson = JSON.stringify($("#dg").datagrid("getData").rows);
            $("#wuliaoShengouDetailsJson").val(goodsJson);
            $("#wuliaoshengoudanhao").val($("#dh").text());
            if ($("#dg").datagrid("getRows").length == 0) {
                $.messager.alert("系统提示", "请添加申购物料!");
                return;
            }
            if (!$("#fm6").form("validate")) {
                $.messager.alert("系统提示", "请填写必填项!");
                return;
            }
            $.ajax({
                url: "/admin/shengoudan/save",
                data: $("#fm6").serialize(),
                type: 'post',
                dataType: 'json',
                success: function (result) {
                    if (result.success) {
                        $.messager.confirm("系统提示", result.msg, function (r) {
                            window.location.reload();
                        })
                    } else {
                        $.messager.alert("系统提示", result.errorInfo);
                    }
                }
            });
        }

        // //  物料类别模块管理
        // function openGoodsTypeAddDialog() {
        //     $("#dlg2").dialog("open").dialog("setTitle", "新增物料类别");
        // }

        // function deleteGoodsType() {
        //     var node = $('#tree').tree('getSelected'); // 获取选中节点
        //     var id = node.id;
        //     $.post("/admin/goodsType/delete", {id: id}, function (result) {
        //         if (result.success) {
        //             $('#tree').tree('reload');
        //         } else {
        //             $.messager.alert("系统提示", "提交失败，请联系管理员！");
        //         }
        //         $('#del').linkbutton('disable');
        //     }, "json");
        // }

        // // 保存物料类别
        // function saveGoodsType() {
        //     var shengoumingcheng = $("#goodsTypeName").val();
        //     if (!$("#fm").form("validate")) {
        //         return;
        //     }
        //     var node = $('#tree').tree('getSelected'); // 获取选中节点
        //     var parentId; // 父节点Id
        //     if (node == null) {
        //         parentId = 1;
        //     } else {
        //         parentId = node.id;
        //     }
        //     $.post("/admin/goodsType/save", {
        //         'shengoumingcheng': shengoumingcheng,
        //         'p_id': parentId
        //     }, function (result) {
        //         if (result.success) {
        //             $('#tree').tree('reload');
        //             closeGoodsTypeDialog();
        //         } else {
        //             $.messager.alert("系统提示", "提交失败，请联系管理员！");
        //         }
        //     }, "json");
        // }

        function closeGoodsTypeDialog() {
            $("#dlg2").dialog("close");
            $("#goodsTypeName").val("");
        }


        function searchGoods() {
            $("#dg3").datagrid('load', {
                "wuliaobianma": $("#s_wuliaobianma").val(),
                "mingchengguige": $("#s_mingchengguige").val()
            });
        }

        function closeGoodsDialog() {
            $("#s_codeOrName").val("");
            $("#dlg").dialog("close");
        }

        function openGoodsChooseDialog() {
            $("#saveAndAddNextBuuton").show();
            var selectedRows = $("#dg3").datagrid("getSelections");
            if (selectedRows.length != 1) {
                $.messager.alert("系统提示", "请选择一个物料！");
                return;
            }
            var row = selectedRows[0];
            $("#action").val("add");
            $("#dlg4").dialog("open").dialog("setTitle", "申购物料");
            $("#fm4").form("load", row);
            $("#lastReturnPrice").val("￥" + row.lastPurchasingPrice);
            $("#price").numberbox("setValue", row.lastPurchasingPrice);
            $("#num").focus();
        }

        function closeGoodsChooseDialog() {
            $("#dlg4").dialog("close");
            resetValue();
        }

        function resetValue() {
            $("#num").numberbox("setValue", "");
            $("#price").val("");
        }

        //添加导入申购明细
        function addGoodsDetailList() {

        }

        function saveGoods(type) {
            var action = $("#action").val();
            if (!$("#fm5").form("validate")) {
                return;
            }
            if (action == "add") {
                var selectedRows = $("#dg3").datagrid("getSelections");
                var row = selectedRows[0];
                // var price = $("#price").numberbox("getValue");
                var number = $("#number").numberbox("getValue");
                var jiaohuodidian = $("#jiaohuodidian").val();
                var zhiliangyaoqiu = $("#zhiliangyaoqiu").val();
                var xuqiuriqi = $("#xuqiuriqi").datebox("getValue");
                var beizhu_sg = $("#beizhu_sg").val();
                var jiagongyigong = $("#jiagongyigong").combobox("getValue");
                var beizhu_final = "";
                if(beizhu_sg){
                    beizhu_final = beizhu_sg;
                }else{
                    beizhu_final = row.beizhu;
                }
                // var total = price * num;
                $('#dg').datagrid('appendRow', {
                    id: row.id,
                    dalei: row.dalei,
                    wuliaobianma: row.wuliaobianma,
                    mingchengguige: row.mingchengguige,
                    jiagongyigong: jiagongyigong,
                    danwei: row.danwei,
                    number: number,
                    kehuishou: row.kehuishou,
                    huishouxiang: row.huishouxiang,
                    beizhu: beizhu_final,
                    founder: row.founder,
                    createtime: row.createtime,
                    jiaohuodidian: jiaohuodidian,
                    zhiliangyaoqiu: zhiliangyaoqiu,
                    xuqiuriqi: xuqiuriqi
                    // total: total,
                    // typeId: row.type.id,
                    // goodsId: row.id,
                    // inventoryQuantity: row.inventoryQuantity,
                    // lastPurchasingPrice: row.lastPurchasingPrice
                });
            } else if (action == "modify") {
                var selectedRows = $("#dg").datagrid("getSelections");
                var rowIndex=$("#rowIndex").val();
                var row = selectedRows[0];
                // var price = $("#price").numberbox("getValue");
                var number = $("#number").numberbox("getValue");
                var jiaohuodidian = $("#jiaohuodidian").val();
                var zhiliangyaoqiu = $("#zhiliangyaoqiu").val();
                var xuqiuriqi = $("#xuqiuriqi").datebox("getValue");
                var beizhu_sg = $("#beizhu_sg").val();
                var jiagongyigong = $("#jiagongyigong").combobox("getValue");
                var beizhu_final = "";
                if(beizhu_sg){
                    beizhu_final = beizhu_sg;
                }else{
                    beizhu_final = row.beizhu;
                }
                $('#dg').datagrid('updateRow', {
                    index: rowIndex,
                    row: {
                        dalei: row.dalei,
                        wuliaobianma: row.wuliaobianma,
                        mingchengguige: row.mingchengguige,
                        jiagongyigong: jiagongyigong,
                        danwei: row.danwei,
                        number: number,
                        kehuishou: row.kehuishou,
                        huishouxiang: row.huishouxiang,
                        beizhu: beizhu_final,
                        founder: row.founder,
                        createtime: row.createtime,
                        jiaohuodidian: jiaohuodidian,
                        zhiliangyaoqiu: zhiliangyaoqiu,
                        xuqiuriqi: xuqiuriqi
                    }
                });
            }
            // setReturnListAmount();
            if (type == 1) {
                closeGoodsDialog();
            }
            closeGoodsChooseDialog();
        }

        $(function () {
            $("#dg").datagrid({

                //之后onLoadSuccess加载这两种方法
                //悬停提示tooltip
                onLoadSuccess: function (data) {
                    $(this).datagrid('tooltip');
                    $(this).datagrid('fixRownumber');
                },
                //双击事件
                onDblClickRow: function (index, row) {
                    $("#saveAndAddNextBuuton").hide();
                    $("#dlg4").dialog("open").dialog("setTitle", "修改申购单物料");
                    $("#fm4").form("load", row);
                    $("#number").numberbox("setValue", row.number);
                    $("#number").focus();
                    $("#action").val("modify");
                    $("#rowIndex").val($("#dg").datagrid("getRowIndex", row));
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    $(this).datagrid("clearSelections"); //取消所有选中项
                    $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                    $('#grid-data').menu('show', {
                        left: e.pageX,//在鼠标点击处显示菜单
                        top: e.pageY
                    });
                    e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                },
            });

        });

        function searchProj() {
            $("#projNameList").datagrid('load', {
                "xiangmumingcheng": $("#projSearch").val()
            });
        }

        // /**
        //
        //   * easyui Datagrid自适应窗口大小
        //   */
        // $(function () {
        //     $(window).resize(function () {
        //         $('#dg3').datagrid('resize', {               //根据自身情况更改
        //             width: $(window).width() - 10,    //根据自身情况更改
        //             height: $(window).height() - 35  //根据自身情况更改
        //         }).datagrid('resize', {
        //             width: $(window).width() - 10,      //根据自身情况更改
        //             height: $(window).height() - 35   //根据自身情况更改
        //         });
        //     });
        //
        // });
        // /**
        //   * easyui Datagrid百分比显示宽度
        //   */
        // function fixWidth(percent)
        // {
        //     return document.body.clientWidth * percent ;//根据自身情况更改
        //
        // } 

    </script>
</head>
<body class="easyui-layout">
<div region="north" style="height: 135px;padding: 10px;border: 0px;padding-top: 20px">
    <fieldset style="border-color: #E7F0FF">
        <legend>申购单号：<span id="dh"></span></legend>
        <form id="fm6" method="post">
            <table cellspacing="8px">
                <tr>
                    <!--<td>-->
                    <!--项目名称：<select class="easyui-combobox" id="supplierId" name="supplier.id" style="width: 200px;"-->
                    <!--required=true-->
                    <!--data-options="required:true,panelHeight:'auto',valueField:'id',textField:'name',url:'/admin/supplier/comboList'"></select>-->
                    <!--</td>-->
                    <td>
                        项目选择：<input type="text" id="projName" name="xiangmumingcheng" style="width: 90px;"
                                    readonly="readonly" onclick="openProjListChoose()" class="easyui-validatebox" required="true"/>
                        <input type="hidden" id="projId"/>
                    </td>
                    <td>
                        &nbsp;&nbsp;申购名称：<input type="text" id="shengoumingcheng" name="shengoumingcheng"
                                                size="10" class="easyui-validatebox"
                                                required="true"/>
                    </td>
                    <td>

                        <!--<input type="text" id="shenhezhuangtai" name="shenhezhuangtai" size="10"-->
                        <!--class="easyui-validatebox" required="true"/>-->
                    </td>


                    <td></td>
                </tr>
                <tr>
                    <td colspan="3">
                        备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：<input type="text" size="78" id="zong_beizhu" name="beizhu"/>
                    </td>

                    <td>
                        <input type="hidden" id="wuliaoshengoudanhao" name="wuliaoshengoudanhao"/>
                        <input type="hidden" id="wuliaoShengouDetailsJson" name="wuliaoShengouDetailsJson"/>
                        &nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:saveReturnGoods()" class="easyui-linkbutton"
                                                   iconCls="icon-ok">保存</a>
                    </td>
                </tr>
            </table>
        </form>
    </fieldset>
</div>
<div region="center" style="padding: 10px;border: 1px">
    <table id="dg" class="easyui-datagrid" style="height: 1200px"
           fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
           fit="true" toolbar="#tb">
        <thead>
        <tr>
            <th field="id" width="30" align="center" sortable="true">编号</th>
            <th field="dalei" width="65" align="center" sortable="true">大类</th>
            <th field="wuliaobianma" width="90" align="center" sortable="true">物料编码</th>
            <th field="mingchengguige" width="130" align="center" sortable="true">名称规格</th>
            <th field="danwei" width="50" align="center" sortable="true">单位</th>
            <th field="number" width="40" align="center" sortable="true">数量</th>
            <th field="jiaohuodidian" width="50" align="center" sortable="true">存放地点</th>
            <th field="xuqiuriqi" width="70" align="center" sortable="true">到货日期</th>
            <th field="zhiliangyaoqiu" width="50" align="center" sortable="true">质量要求</th>
            <th field="beizhu" width="50" align="center" sortable="true">备注</th>
            <th field="jiagongyigong" width="50" align="center" sortable="true">甲供乙供</th>
            <!--<th field="createtime" width="70" align="center" sortable="true">创建时间</th>-->
        </tr>
        </thead>
    </table>
    <div id="tb">
        <div style="padding: 2px">
            <a href="javascript:openShengouDetailsAddDialog()" class="easyui-linkbutton" iconCls="icon-add"
               plain="true">添加</a>
            <a href="javascript:uploadidalogonline()" class="easyui-linkbutton" iconCls="icon-add" plain="true">批量导入</a>
            <a href="javascript:openShengouDetailsModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit"
               plain="true">修改</a>
            <a href="javascript:deleteShengouDetails()" class="easyui-linkbutton" iconCls="icon-remove"
               plain="true">删除</a>
            <!--<a href="javascript:addGoodsDetailList()" class="easyui-linkbutton" iconCls="icon-add" plain="true">明细导入</a>-->
        </div>
    </div>
</div>

<div id="dlg" class="easyui-dialog" style="width:1200px;height:460px;"
     closed="true" data-options="onClose:function(){$('#s_codeOrName').val('');}">
    <div class="easyui-layout" style="width:100%;height:100%;">

        <div region="north" style="height: 50px;">
            <div style="padding-top: 8px;padding-left: 40px;">
                &nbsp;物料编码：&nbsp;<input type="text" id="s_wuliaobianma" size="30"
                                        onkeydown="if(event.keyCode==13) searchGoods()"/>
                &nbsp;名称规格：&nbsp;<input type="text" id="s_mingchengguige" size="30"
                                        onkeydown="if(event.keyCode==13) searchGoods()"/>
                <a href="javascript:searchGoods()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
            </div>
        </div>
        <div region="west" style="width: 200px" title="物料类别" split="true" data-options="collapsible:false">
            <div style="overflow-x: auto; overflow-y: auto; height: 90%; width:98%;">
                <ul id="tree" class="easyui-tree" style="padding: 10px"></ul>
            </div>

        </div>
        <div region="center">
            <table id="dg3" title="物料列表" class="easyui-datagrid"
                   fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
                   url="/admin/dwuliao/getSelective" fit="true" toolbar="#tb3">
                <thead>
                <tr>
                    <th field="id" align="center" sortable="true" hidden="hidden">编号</th>
                    <th field="dalei"  width=10% align="center" sortable="true">大类</th>
                    <th field="wuliaobianma" width=10% align="center" sortable="true">物料编码</th>
                    <th field="mingchengguige" width=20% align="center" sortable="true">名称规格</th>
                    <th field="danwei" width=10% align="center" sortable="true">单位</th>
                    <th field="kehuishou" width=10% align="center" sortable="true">可回收</th>
                    <th field="huishouxiang" width=10% align="center" sortable="true">回收项</th>
                    <th field="beizhu" width=10% align="center" sortable="true">备注</th>
                    <th field="founder" width=10% align="center" sortable="true">创建人</th>
                    <th field="createtime" width=10% align="center" sortable="true">创建时间</th>
                </tr>
                </thead>
            </table>
            <div id="tb3">
                <div>
                    <a href="javascript:openGoodsChooseDialog()" class="easyui-linkbutton" iconCls="icon-ok"
                       plain="true">选择</a>
                </div>
            </div>
        </div>
    </div>
</div>

<!--详细弹出窗及按钮组-->
<div id="dlg2" class="easyui-dialog" style="width: 500px;height:150px;padding: 10px 20px"
     closed="true" buttons="#dlg-buttons2" data-options="onClose:function(){resetTypeValue()}">
    <form id="fm2" onkeydown="if(event.keyCode==13)saveOrUpdate()">
        <table cellspacing="8px">
            <tr>
                <td>项目名称：</td>
                <td colspan="4">
                    <input type="text" id="name" name="name" class="easyui-validatebox" required="true"
                           style="width: 350px;"/>
                </td>
            </tr>
            <!--<tr>-->
            <!--<td valign="top">备注：</td>-->
            <!--<td colspan="4">-->
            <!--<textarea rows="5" cols="47" id="remarks" name="remarks"></textarea>-->
            <!--</td>-->
            <!--</tr>-->
        </table>
    </form>
</div>

<div id="dlg-buttons2">
    <a href="javascript:saveGoodsType()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
    <a href="javascript:closeGoodsTypeDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>

<!--添加或修改物料信息,这里是设定多少个申购物料-->
<div id="dlg4" class="easyui-dialog" style="width:550px;height:465px;padding: 5px 5px"
     closed="true" buttons="#dlg-buttons4" data-options="onClose:function(){resetValue()}">

    <fieldset style="border-color: #E7F0FF">
        <legend>物料信息</legend>
        <form id="fm4" method="post">
            <table cellspacing="8px">
                <tr>
                    <td width="60">大类：</td>
                    <td>
                        <input type="text" id="dalei" name="dalei" readonly="readonly" class="easyui-validatebox"
                                size="10"/>
                    </td>
                    <td width="80">物料编码：</td>
                    <td><input type="text" id="wuliaobianma" name="wuliaobianma" readonly="readonly"
                               class="easyui-validatebox"  size="15"/></td>
                </tr>
                <tr>
                    <td width="80">名称规格：</td>
                    <td colspan="4">
                        <input type="text" id="mingchengguige" name="mingchengguige" readonly="readonly"
                               class="easyui-validatebox" required="true" size="20"/>
                    </td>
                </tr>
                <tr>
                    <td width="80">单位：</td>
                    <td>
                        <!--<input type="text" id="danwei" name="danwei" class="easyui-validatebox" required="true" size="10"  />-->
                        <select class="easyui-combobox" required="true" id="danwei" name="danwei" readonly="readonly"
                                style="width: 80px;"
                                data-options="panelHeight:'auto',editable:false,valueField:'danwei',textField:'danwei',url:'/admin/wuliaodanwei/comboList'">
                        </select>
                        <!--<a href="javascript:openChooseGoodsUnitDialog()" class="easyui-linkbutton" iconCls="icon-search"  plain="true"></a>-->
                    </td>
                </tr>
                <tr>
                    <td width="60">可回收：</td>
                    <td>
                        <select id="kehuishou" class="easyui-combobox" name="kehuishou" readonly="readonly"
                                panelHeight="auto" panelMaxHeight="200px" style="width:80px;">
                            <option value="不可回收">不可回收</option>
                            <option value="可回收">可回收</option>
                        </select>
                        <!--<input type="text" id="kehuishou" name="kehuishou" class="easyui-validatebox" required="true" size="10" />-->
                    </td>
                    <td width="60">回收项：</td>
                    <td><input type="text" id="huishouxiang" name="huishouxiang" readonly="readonly"
                               class="easyui-validatebox"  size="10"/></td>
                </tr>
                <!--<tr>-->
                <!--<td width="60">备注：</td>-->
                <!--<td>-->
                <!--<input type="text" id="beizhu" name="beizhu" readonly="readonly" class="easyui-validatebox"-->
                <!--size="10"/>-->
                <!--</td>-->
                <!--<td width="60">创建人：</td>-->
                <!--<td>-->
                <!--<input type="text" id="founder_wuliao" name="founder" readonly="readonly"-->
                <!--class="easyui-validatebox" size="10"/>-->
                <!--</td>-->
                <!--</tr>-->
            </table>
        </form>
    </fieldset>
    <div style="padding-left: 12px;padding-top: 10px">
        <form id="fm5" method="post">
            <table cellspacing="8px">
                <td><input type="hidden" id="action"/><input type="hidden" id="rowIndex"/></td>
                <tr>
                    <td>申购数量：</td>
                    <td><input type="text" id="number" name="number" class="easyui-numberbox" data-options="min:1"
                               required="true" size="10"/></td>
                    <td>交货地点：</td>
                    <td><input type="text" id="jiaohuodidian" name="jiaohuodidian" data-options="min:1"
                               required="true" size="10"/></td>
                </tr>
                <tr>
                    <td>质量要求：</td>
                    <td><input type="text" id="zhiliangyaoqiu" name="zhiliangyaoqiu" data-options="min:1"
                               required="true" size="10"/></td>
                    <td>需求日期：</td>
                    <td><input type="text" id="xuqiuriqi" name="xuqiuriqi" class="easyui-datebox"
                               data-options="editable:false"
                               required="true" size="10"/></td>
                </tr>
                <tr>
                    <td>甲供乙供：</td>
                    <td>
                        <select class="easyui-combobox" id="jiagongyigong" required="true"
                                name="jiagongyigong"
                                style="width: 160px;" editable="false" panelHeight="auto">
                            <option value="甲供">甲供</option>
                            <option value="乙供">乙供</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>申购备注：</td>
                    <td><input type="text" id="beizhu_sg" name="beizhu" data-options="min:1"
                               size="20"/></td>
                </tr>
            </table>
        </form>
    </div>
</div>

<div id="dlg-buttons4">
    <a id="saveAndAddNextBuuton" href="javascript:saveGoods(2)" class="easyui-linkbutton"
       iconCls="icon-ok">保存并新增下一物料</a>
    <a href="javascript:saveGoods(1)" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
    <a href="javascript:closeGoodsChooseDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>

<!--查询项目列表-->
<div id="projList" class="easyui-dialog" style="width:800px;height:460px;"
     closed="true" data-options="onClose:function(){$('#s_codeOrProjName').val('');}">
    <div class="easyui-layout" style="width:100%;height:100%;">

        <div region="north" style="height: 50px;">
            <div style="padding-top: 8px;padding-left: 40px;">
                &nbsp;项目名称：&nbsp;<input type="text" id="projSearch" size="30"
                                        onkeydown="if(event.keyCode==13) searchProj()"/>
                <a href="javascript:searchProj()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
            </div>
        </div>
        <div region="west" style="width: 200px" title="项目分类" split="true" data-options="collapsible:false">
            <div style="overflow-x: auto; overflow-y: auto; height: 90%; width:98%;">
                <ul id="projTree" class="easyui-tree" style="padding: 10px"></ul>
            </div>
            <div style="position:absolute;bottom: 10px;left: 15px">
                <a href="javascript:saveProjChoose(1)" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">选择</a>
                <!--<a id="del" href="javascript:deleteGoodsType()" class="easyui-linkbutton" data-options="iconCls:'icon-remove',disabled:true">删除</a>-->
            </div>
        </div>
        <div region="center">
            <table id="projNameList" title="项目列表" class="easyui-datagrid"
                   fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
                   url="/admin/dproject/getSelective" fit="true" toolbar="#tb4">
                <thead>
                <tr>
                    <th field="id" width="30" hidden=true align="center">编号</th>
                    <th field="xiangmumingcheng" width="150" align="center">项目名称</th>
                    <th field="createtime" width="90" align="left">创建时间</th>
                    <!--<th field="model" width="50" align="center">型号</th>-->
                    <!--<th field="unit" width="50" align="center" >单位</th>-->
                    <!--<th field="lastPurchasingPrice" width="50" align="center" formatter="formatLastPurchasingPrice">上次进价</th>-->
                    <!--<th field="purchasingPrice" width="50" align="center" formatter="formatPurchasingPrice">成本均价</th>-->
                    <!--<th field="inventoryQuantity" width="50" align="center">库存数量</th>-->
                </tr>
                </thead>
            </table>
            <div id="tb4">
                <div>
                    <a href="javascript:saveProjChoose(2)" class="easyui-linkbutton" iconCls="icon-ok"
                       plain="true">选择</a>
                </div>
            </div>
        </div>
    </div>
</div>

<!--大屏幕上右键datagrid dlg-->
<div id="grid-data" class="easyui-menu" style="width: 80px; display: none;">
    <div id="grid-data-edit" href="javascript:openShengouDetailsModifyDialog()" data-options="iconCls:'icon-edit'">修改</div>
    <div id="grid-data-delete" href="javascript:deleteShengouDetails()" data-options="iconCls:'icon-remove'" plain="true">删除
    </div>
</div>
<!--二级菜单右键弹出-->
<div id="tree-2" class="easyui-menu" style="width: 80px; display: none;">
    <!--<div id="tree-2-delete" href="javascript:deleteType()" data-options="iconCls:'icon-remove'">删除二级菜单</div>-->
</div>
<!--一级菜单右键弹出-->
<div id="tree-1" class="easyui-menu" style="width: 80px; display: none;">
    <!--<div id="tree-1-add-2" href="javascript:openTypeAddDialog()" data-options="iconCls:'icon-add'">添加二级菜单</div>-->
    <!--<div id="tree-1-delete" href="javascript:deleteType()" data-options="iconCls:'icon-remove'">删除一级菜单</div>-->
</div>
<!--树形菜单右键弹出-->
<div id="tree-0" class="easyui-menu" style="width: 80px; display: none;">
    <!--<div id="tree-0-add-1" href="javascript:openTypeAddDialog(0)" data-options="iconCls:'icon-add'">添加一级菜单</div>-->
    <!--<div id="tree-0-refresh" href="javascript:reloadTree()" data-options="iconCls:'icon-reload'">重新加载类别</div>-->
</div>

<!--上传excel的弹出窗-->
<div id="uploadonlineinfo" class="easyui-window" style="width:380px;padding:10px 40px" closed="true">

    <form id="fam" method="post" enctype="multipart/form-data">

        <!--<input class="easyui-filebox" id="onlinefilename" name="onlinefilename" data-options="prompt:'文件上传'"-->
        <!--style="width:100%" />-->
        <input type="file"
               id="uploadfile" name="uploadfile" style="width:100%"/>
    </form>
    <br>

    <div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;">
        <button id="uploadBtn" class="easyui-b" data-options="iconCls:'icon-ok'"
                style="width:80px">上传
        </button>
    </div>
    <br>
    <p style="text-align: center"><a href="/static/xlsx/wuliaoshengoudanpiliangdaoruwuliaomoban.xlsx">下载批量导入申购明细excel模板</a></p>

</div>

</body>
<script>

    /* 上传excel的窗口打开操作 */
    function uploadidalogonline() {
        // var node = $('#tree').tree('getSelected'); // 获取选中节点
        // if(node==undefined){
        //     $.messager.alert("系统提示","请选中物料类别！");
        //     return;
        // }
        $('#uploadonlineinfo').window('open').dialog('setTitle', '文件上传');
    }

    // 上传文件
    $("#uploadBtn").click(uploadonline);

    // 上传操作
    function uploadonline() {
        /* var node = $('#tree').tree('getSelected'); // 获取选中节点
         if(node==undefined){
             $.messager.alert("系统提示","请选中物料类别！");
             return;
         }
         console.log("node.id:"+node.id);
         var parent = $('#tree').tree('getParent',node.target);//父节点
         console.log("parent:"+parent);
         var w_id = node.id;
         var o_id;
         if(parent){
             o_id = parent.id;
         }else{
             o_id = node.id; //一级菜单下没有父菜单,则使用其自身的id
         }*/

        console.log("uploadonline");
        // var add = '/excel/importExcel';
        var theExcel = $("#uploadfile")[0].files[0];
        console.log(theExcel);
        var formData = new FormData();
        formData.append("theExcel", theExcel);
        formData.append("page", 1);
        formData.append("rows", 10);
        console.log(formData);
        // if ("undefined" != typeof(uploadFile) && uploadFile != null && uploadFile != "") {
        $.ajax({
            url: '/excel/importExcel/wuliaoshengoudanmingxi',
            type: 'POST',
            data: formData,
            async: false,
            cache: false,
            contentType: false, //不设置内容类型
            processData: false, //不处理数据
            success: function (data) {
                if(data.total>0){
                    $.messager.alert("系统提示","操作成功！");
                    //成功导入,新增数据到wuliaokucunrizhi 去重 同时根据w_id,o_id 查
                    $("#dg").datagrid('reload');
                    var rows = data.rows;
                    for (index in data.rows){
                        console.log(rows);
                        $('#dg').datagrid('appendRow', {
                            id: rows[index].id,
                            dalei: rows[index].dalei,
                            wuliaobianma: rows[index].wuliaobianma,
                            mingchengguige: rows[index].mingchengguige,
                            jiagongyigong: rows[index].jiagongyigong,
                            danwei: rows[index].danwei,
                            number: rows[index].number,
                            kehuishou: rows[index].kehuishou,
                            huishouxiang: rows[index].huishouxiang,
                            beizhu: rows[index].beizhu,
                            founder: rows[index].founder,
                            createtime: rows[index].createtime,
                            jiaohuodidian: rows[index].jiaohuodidian,
                            zhiliangyaoqiu: rows[index].zhiliangyaoqiu,
                            xuqiuriqi: rows[index].xuqiuriqi
                            // total: total,
                            // typeId: row.type.id,
                            // goodsId: row.id,
                            // inventoryQuantity: row.inventoryQuantity,
                            // lastPurchasingPrice: row.lastPurchasingPrice
                        });

                    }
                    $("#uploadonlineinfo").dialog("close");
                }else{
                    $.messager.alert("系统提示","操作失败！");
                    $("#dg").datagrid('reload');
                    $("#uploadonlineinfo").dialog("close");
                }
            }
        });
    }


</script>
</html>